package ferp.android.views;

import android.content.Context;
import android.view.ViewGroup;
import ferp.android.GUI;
import ferp.core.card.Card;
import ferp.core.game.Game;

/**
 * User: igorgok
 * Date: 6/14/12 3:59 PM
 */
class TrickView extends ViewGroup
{
  public TrickView(Context context, TableView parent)
  {
    super(context);

    for (int i = 0; i < Game.PLAYERS; ++i)
    {
      cv[i] = new CardView(context, parent);
      cv[i].setVisibility(INVISIBLE);
      cv[i].setEnabled(false);

      addView(cv[i]);
    }
  }

  public void show(int id, Card card)
  {
    //Log.log.debug(Log.TAG, "tv show id " + id + " card " + card);

    // put the card on top of corresponding trick card
    CardView v = cv[id];

    v.set(card, true);
    v.bringToFront();

    v.setVisibility(VISIBLE);
  }

  public void hide()
  {
    for (CardView v : cv)
    {
      //GUI.toast(getContext(), "Hiding card " + v.card());
      v.setVisibility(INVISIBLE);
    }
  }

  // get card view by player id
  public CardView getTargetCardView(int id)
  {
    return cv[id];
  }

  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b)
  {
    // "t" carries the offset which has to be used to handle the trick shift
    cv[0].layout(GUI.center(CardView.WIDTH, 0, getWidth()), getHeight() - CardView.HEIGHT);
    cv[1].layout(0, 0);
    cv[2].layout(getWidth() - CardView.WIDTH, 0);
  }

  private final CardView[] cv = new CardView[Game.PLAYERS];
}
